'''
Created on 2017年5月23日

@author: lingxiang
'''
from flask import Flask, jsonify, request
from api import app
from proxyManager.ProxyManager import  ProxyManager


'''
classdocs
'''
api_list = {
'get': u'get an usable proxy',
'refresh': u'refresh proxy pool',
'get_all': u'get all proxy from proxy pool',
'delete?proxy=127.0.0.1:5000': u'delete an unable proxy',
    
}
pm=ProxyManager()
def __init__():
    '''
    Constructor
    '''
@app.route('/')
def index():
    return jsonify(api_list)
    
    
@app.route('/get/')
def get():     #从代理池中返回一个代理IP
    
    proxy = ProxyManager().get_one()
    return proxy

    
    
@app.route('/refresh/')
def refresh():  
# 刷新  重新获取新代理IP  并验证 
    return ProxyManager().refresh_ip_pool()  
    
    
    
@app.route('/get_all/<size>', methods=['GET'])
def getAll_size(size):    #返回代理池中所有的代理IP
    proxies=ProxyManager().getAll(size)
    return jsonify(list(proxies))

    
    
@app.route('/delete/<proxy>', methods=['GET'])
def delete(proxy): 
    ipList=ProxyManager().delete(proxy)  
    return jsonify(list(ipList))
         
def run():
    app.run(host='0.0.0.0', port=5000) 
    

if __name__ == '__main__':
    run()
    
   
    
